import uthread
import uiconst
import uiutil
import uicls
import log

class VideoCore(uicls._BaseDecoCore, uicls._GetDecoMetaclassInst('trinity.UIVideo')):
    __guid__ = 'uicls.VideoCore'
    default_name = 'video'
    default_align = uiconst.RELATIVE
    default_state = uiconst.UI_NORMAL
    default_loop = False

    def ApplyAttributes(self, attributes):
        uicls._BaseDecoCore.ApplyAttributes(self, attributes)
        videoPath = attributes.get('videoPath', None)
        if (videoPath is not None):
            self.videoPath = videoPath
        self.loop = attributes.get('loop', self.default_loop)
        (l, t, w, h,) = attributes.get('pos', (0,
         0,
         uicore.uilib.desktop.width,
         uicore.uilib.desktop.height))
        self.left = l
        self.top = t
        self.width = w
        self.height = h



    def SetVideoPath(self, videoPath):
        self.videoPath = videoPath



    def _OnClose(self):
        uicls._BaseDecoCore._OnClose(self)
        if not self.isFinished:
            self.Pause()



    def IsPlaying(self):
        if (self.isFinished or self.isPaused):
            return False
        else:
            return True




